﻿namespace primenumber
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //thenum 接受最大质数
            int thenum = 0;bool prime = true;
            //开始时间
            double setupsecond = DateTime.Now.Second;

            double setupmsecond = DateTime.Now.Millisecond;
            //从2开始寻找100000内最大质数
            for (int num =2;num<=100000;num++)
            {
                for(int commonfactor = 2;commonfactor<=num/2;commonfactor++)
                {
                    if(num%commonfactor ==0)
                    {
                        prime = false;
                        break;
                    }
                    else
                        prime = true;
                }
                if (prime)
                    thenum = num;
            }
            double endupsecond = DateTime.Now.Second;

            double endupmsecond = DateTime.Now.Millisecond;
            //统计时间
            double spendtime = (endupsecond - setupsecond) + (endupmsecond - setupmsecond) * 0.001;
            Console.WriteLine("你一共用时" + spendtime + "秒");
            Console.WriteLine(thenum);
        }
    }
}